import { DELETE_USERINFO, SAVE_USERINFO } from "../action_types";

let user = JSON.parse(localStorage.getItem("user"));
let isLogin = localStorage.getItem("isLogin");

let userinfo = {
    user: user || "",
    isLogin: isLogin || false
}
export default function loginAndGetUserinfo(preState = userinfo, action) {
    const { type, data } = action
    switch (type) {
        case SAVE_USERINFO:
            return { user: data, isLogin: true };
        case DELETE_USERINFO:
            return { user: "", isLogin: false };
        default:
            return preState;
    }
}